using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Scripting;

namespace UserScripts
{
    public class Login : ScriptBase
    {
        /// <summary>
        /// Method to execute when a player has logged on.
        /// </summary>
        /// <param name="actor"></param>
        public void OnLogin(Actor actor)
        {
            // Default player setup
            actor.CreateChatTab(0, "Main", 60);
            actor.SwitchToTab(0);

            // If the player doesn't have a torch, then give him on.
            if(actor.HasItem("Torch") == 0)
                actor.GiveItem("Torch", 1);

            // Log the entrance
            RCScript.Log(string.Format("OnLogin(\"{0}\") Called.", actor.Name)); 
			
			//Set Initial Globals for Actor
			SetInitialGlobals(actor);
        }
        static void SetInitialGlobals(Actor actor)
        {
            CustomAttributes attrib = new CustomAttributes();
            GlobalInteraction useglobal = new GlobalInteraction();
            if (!actor.Globals.ContainsKey("StrBonus"))
            {
                useglobal.SetSingleGlobal(actor, "StrBonus", 0);
            }
            if (!actor.Globals.ContainsKey("StrPenalty"))
            {
                useglobal.SetSingleGlobal(actor, "StrPenalty", 0);
            }
            if (!actor.Globals.ContainsKey("DexBonus"))
            {
                useglobal.SetSingleGlobal(actor, "DexBonus", 0);
            }
            if (!actor.Globals.ContainsKey("DexPenalty"))
            {
                useglobal.SetSingleGlobal(actor, "DexPenalty", 0);
            }
            if (!actor.Globals.ContainsKey("TouBonus"))
            {
                useglobal.SetSingleGlobal(actor, "TouBonus", 0);
            }
            if (!actor.Globals.ContainsKey("TouPenalty"))
            {
                useglobal.SetSingleGlobal(actor, "TouPenalty", 0);
            }
            if (!actor.Globals.ContainsKey("PerBonus"))
            {
                useglobal.SetSingleGlobal(actor, "PerBonus", 0);
            }
            if (!actor.Globals.ContainsKey("PerPenalty"))
            {
                useglobal.SetSingleGlobal(actor, "PerPenalty", 0);
            }
            if (!actor.Globals.ContainsKey("WilBonus"))
            {
                useglobal.SetSingleGlobal(actor, "WilBonus", 0);
            }
            if (!actor.Globals.ContainsKey("WilPenalty"))
            {
                useglobal.SetSingleGlobal(actor, "WilPenalty", 0);
            }
            if (!actor.Globals.ContainsKey("ChaBonus"))
            {
                useglobal.SetSingleGlobal(actor, "ChaBonus", 0);
            }
            if (!actor.Globals.ContainsKey("ChaPenalty"))
            {
                useglobal.SetSingleGlobal(actor, "ChaPenalty", 0);
            }
            if (!actor.Globals.ContainsKey("InitPenalty"))
            {
                useglobal.SetSingleGlobal(actor, "InitPenalty", 0);
            }
            if (!actor.Globals.ContainsKey("InitBonus"))
            {
                useglobal.SetSingleGlobal(actor, "InitBonus", 0);
            }
            if (!actor.Globals.ContainsKey("AggressiveStance"))
            {
                actor.Globals["AggressiveStance"] = BitConverter.GetBytes(false);
            }
            if (!actor.Globals.ContainsKey("DefensiveStance"))
            {
                actor.Globals["DefensiveStance"] = BitConverter.GetBytes(false);
            }
            if (!actor.Globals.ContainsKey("Harried"))
            {
                actor.Globals["Harried"] = BitConverter.GetBytes(false);
            }
            if (!actor.Globals.ContainsKey("KnockedDown"))
            {
                actor.Globals["KnockedDown"] = BitConverter.GetBytes(false);
            }
            if (!actor.Globals.ContainsKey("PhysicalDefense"))
            {
                int pd = attrib.GetCustomAttributes(actor, "PhysicalDefense");
                useglobal.SetSingleGlobal(actor, "PhysicalDefense", pd);
                RCScript.Log(string.Format("Physical Defense Global(\"{0}\") Called.", actor.Name));
            }
            if (!actor.Globals.ContainsKey("SpellDefense"))
            {
                int spd = attrib.GetCustomAttributes(actor, "SpellDefense");
                useglobal.SetSingleGlobal(actor, "SpellDefense", spd);
                RCScript.Log(string.Format("Spell Defense Global(\"{0}\") Called.", actor.Name));                
            }
            if (!actor.Globals.ContainsKey("SocialDefense"))
            {
                int socd = attrib.GetCustomAttributes(actor, "SocialDefense");
                useglobal.SetSingleGlobal(actor, "SocialDefense", socd);
                RCScript.Log(string.Format("Social Defense Global(\"{0}\") Called.", actor.Name));  
            }
            if (!actor.Globals.ContainsKey("CarryingCapacity"))
            {
                int cc = attrib.GetCustomAttributes(actor, "CarryingCapacity");
                useglobal.SetSingleGlobal(actor, "CarryingCapacity", cc);
                RCScript.Log(string.Format("Carrying Capacity Global(\"{0}\") Called.", actor.Name));  
            }
            if (!actor.Globals.ContainsKey("DeathRating"))
            {
                int dr = attrib.GetCustomAttributes(actor, "DeathRating");
                useglobal.SetSingleGlobal(actor, "DeathRating", dr);
                RCScript.Log(string.Format("Death Rating Global(\"{0}\") Called.", actor.Name));  
            }
            if (!actor.Globals.ContainsKey("UnconsciousnessRating"))
            {
                int ur = attrib.GetCustomAttributes(actor, "UnconsciousnessRating");
                useglobal.SetSingleGlobal(actor, "UnconsciousnessRating", ur);
                RCScript.Log(string.Format("Unconsciousness Rating Global(\"{0}\") Called.", actor.Name));  
            }
            if (!actor.Globals.ContainsKey("WoundThreshold"))
            {
                int wt = attrib.GetCustomAttributes(actor, "WoundThreshold");
                useglobal.SetSingleGlobal(actor, "WoundThreshold", wt);
                RCScript.Log(string.Format("Wound Threshold Global(\"{0}\") Called.", actor.Name));  
            }
            if (!actor.Globals.ContainsKey("RecoveryTestsPerDay"))
            {
                int rt = attrib.GetCustomAttributes(actor, "RecoveryTestsPerDay");
                useglobal.SetSingleGlobal(actor, "RecoveryTestsPerDay", rt);
                RCScript.Log(string.Format("Recovery Tests Per Day Global(\"{0}\") Called.", actor.Name));  
            }
            if (!actor.Globals.ContainsKey("MysticArmor"))
            {
                int ma = attrib.GetCustomAttributes(actor, "MysticArmor");
                useglobal.SetSingleGlobal(actor, "MysticArmor", ma);
                RCScript.Log(string.Format("Mystic Armor Global(\"{0}\") Called.", actor.Name));  
            }
            if (!actor.Globals.ContainsKey("Initiative"))
            {
                int init = attrib.GetCustomAttributes(actor, "Initiative");
                useglobal.SetSingleGlobal(actor, "Initiative", init);
                RCScript.Log(string.Format("Initiative Global(\"{0}\") Called.", actor.Name));
            }
        }
    }
}